<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="../css/weui.css"/>
    <link rel="stylesheet" href="../css/weuix.css"/>

    <script src="../js/zepto.min.js"></script>

    <script src="../js/zepto.weui.js"></script>

    <script>

        $(function(){

            var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)" onclick="removeimg(this)"></li>';
          var      $uploaderInput = $("#uploaderInput"); //上传按钮+
         var       $uploaderFiles = $("#uploaderFiles");    //图片列表
            var $galleryImg = $(".weui-gallery__img");//相册图片地址
            var $gallery = $(".weui-gallery");
            $uploaderInput.on("change", function(e){
                var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
                for (var i = 0, len = files.length; i < len; ++i) {
                    var file = files[i];

                    if (url) {
                        src = url.createObjectURL(file);
                    } else {
                        src = e.target.result;
                    }

                    $uploaderFiles.append($(tmpl.replace('#url#', src)));
                }
            });
            $uploaderFiles.on("click", "li", function(){
                $galleryImg.attr("style", this.getAttribute("style"));
                console.log(this)
                $gallery.fadeIn(100);
            });
            $gallery.on("click", function(){
                $gallery.fadeOut(100);
            });

        });

        function removeimg(obj){
            $.confirm('您确定要删除吗?', '确认删除?', function() {$(obj).remove(); $(".weui-gallery").fadeOut(100);});
            return false;
        }

    </script>
</head>

<body ontouchstart>
<div class="page-hd">
    <h1 class="page-hd-title">
        图片上传
    </h1>
    <p class="page-hd-desc"></p>
</div>


<div class="weui-uploader">
    <div class="weui-uploader__hd">
        <p class="weui-uploader__title">图片上传</p>
        <div class="weui-uploader__info">0/2</div>
    </div>
    <div class="weui-uploader__bd">
        <ul class="weui-uploader__files" id="uploaderFiles">
            <li class="weui-uploader__file" style="background-image:url(../images/pic_160.png)" onclick="removeimg(this)"></li>
            <li class="weui-uploader__file" style="background-image:url(../images/pic_160.png)" onclick="removeimg(this)"></li>
            <li class="weui-uploader__file" style="background-image:url(../images/pic_160.png)" onclick="removeimg(this)"></li>
            <li class="weui-uploader__file weui-uploader__file_status" style="background-image:url(../images/pic_160.png)" onclick="removeimg(this)">
                <div class="weui-uploader__file-content">
                    <i class="weui-icon-warn"></i>
                </div>
            </li>
            <li onclick="removeimg(this)" class="weui-uploader__file weui-uploader__file_status" style="background-image:url(../images/pic_160.png)">
                <div class="weui-uploader__file-content">50%</div>
            </li>
        </ul>
        <div class="weui-uploader__input-box">
            <input id="uploaderInput" class="weui-uploader__input" accept="image/*" multiple="" type="file">
        </div>
    </div>
</div>

<div class="weui-gallery" style="display: none">
    <span class="weui-gallery__img"></span>
    <div class="weui-gallery__opr">
    </div>
</div>

<br>
<br>
<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__links">
        <a href="../index.html" class="weui-footer__link">WeUI首页</a>
    </p>
    <p class="weui-footer__text">Copyright &copy; Yoby</p>
</div>
</body>
</html>